/********************\
* Author:Dzlua
* QQ:505544956
* Time:2017/03/19
\*********************/
#ifndef __SD_WINDOW_H__
#define __SD_WINDOW_H__
#pragma once

#include "SDIScript.h"

namespace DuiLib {

class UILIB_API SDWindow :
        public SDWindowBase,
        public CWindowWnd,
        public INotifyUI,
        public IMessageFilterUI,
        public IDialogBuilderCallback,
        public IQueryControlText
{
    friend class SDEngine;
    friend class CControlUI;
    friend class CDialogBuilder;
public:
    SDWindow(LPCTSTR name);
    virtual ~SDWindow();
public:
    //file or str
    BOOL BuildWindow(LPCTSTR xml);
    //file or str
    CControlUI* BuildControl(LPCTSTR xml);
    void Minimize();
    void Maximize();
    void Restore();

public:
    void* DoScript(SPDUI_MSG msg, void* data1 = 0, void* data2 = 0);
    void* DoScript(SPDUI_MSG msg, WPARAM wParam, LPARAM lParam);
public:
    virtual LONG GetStyle();
    //CWindowWnd::
    virtual UINT GetClassStyle() const;
    virtual BOOL IsStaticControl(CControlUI *pControl);
protected:
    virtual LRESULT OnClose(WPARAM wParam, LPARAM lParam, BOOL& bHandled);
    virtual LRESULT OnDestroy(WPARAM wParam, LPARAM lParam, BOOL& bHandled);
#if defined(WIN32) && !defined(UNDER_CE)
    virtual LRESULT OnNcActivate(WPARAM wParam, LPARAM lParam, BOOL& bHandled);
    virtual LRESULT OnNcCalcSize(WPARAM wParam, LPARAM lParam, BOOL& bHandled);
    virtual LRESULT OnNcPaint(WPARAM wParam, LPARAM lParam, BOOL& bHandled);
    virtual LRESULT OnNcHitTest(WPARAM wParam, LPARAM lParam, BOOL& bHandled);
    virtual LRESULT OnGetMinMaxInfo(WPARAM wParam, LPARAM lParam, BOOL& bHandled);
    virtual LRESULT OnMouseWheel(WPARAM wParam, LPARAM lParam, BOOL& bHandled);
    virtual LRESULT OnMouseHover(WPARAM wParam, LPARAM lParam, BOOL& bHandled);
#endif
    virtual LRESULT OnSize(WPARAM wParam, LPARAM lParam, BOOL& bHandled);
    virtual LRESULT OnChar(WPARAM wParam, LPARAM lParam, BOOL& bHandled);
    virtual LRESULT OnSysCommand(WPARAM wParam, LPARAM lParam, BOOL& bHandled);
    virtual LRESULT OnCreate(WPARAM wParam, LPARAM lParam, BOOL& bHandled);
    virtual LRESULT OnKeyDown(WPARAM wParam, LPARAM lParam, BOOL& bHandled);
    virtual LRESULT OnKeyUp(WPARAM wParam, LPARAM lParam, BOOL& bHandled);
    virtual LRESULT OnLButtonDown(WPARAM wParam, LPARAM lParam, BOOL& bHandled);
    virtual LRESULT OnLButtonUp(WPARAM wParam, LPARAM lParam, BOOL& bHandled);
    virtual LRESULT OnKillFocus(WPARAM wParam, LPARAM lParam, BOOL& bHandled);
    virtual LRESULT OnSetFocus(WPARAM wParam, LPARAM lParam, BOOL& bHandled);
    virtual LRESULT OnMouseMove(WPARAM wParam, LPARAM lParam, BOOL& bHandled);
protected:
    virtual void OnCreate();
    virtual void OnZoomed(bool bZoomed);
    virtual void OnNotify(TNotifyUI& msg);
    virtual CControlUI* OnCreateControl(LPCTSTR pstrClass);
	virtual LRESULT OnHandleMessage(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled);
public:
    //CWindowWnd::
    virtual LPCTSTR GetWindowClassName() const;
    //CWindowWnd::
    virtual LRESULT HandleMessage(UINT uMsg, WPARAM wParam, LPARAM lParam);
    //CWindowWnd::
    virtual void OnFinalMessage(HWND hWnd);
    //INotifyUI::
    virtual void Notify(TNotifyUI& msg);
    //IMessageFilterUI::
    virtual LRESULT MessageHandler(UINT uMsg, WPARAM wParam, LPARAM lParam, bool& bHandled);
    //IDialogBuilderCallback::
    virtual CControlUI* CreateControl(LPCTSTR pstrClass);
    //IQueryControlText::
    virtual LPCTSTR QueryControlText(LPCTSTR lpstrId, LPCTSTR lpstrType);
protected:
    void SetAutoDelete(bool bAutoDelete);
    bool IsAutoDelete();
    // called by CControlUI::~CControlUI
    void OnRemoveControl(CControlUI* ctrl);
    // called by CDialogBuilder::_Parse
    void OnAfterCreateControl(CControlUI* ctrl, LPCTSTR ctrlname);
protected:
    CDuiString m_name;
    bool m_bAutoDelete;
};

}
#endif //__SD_WINDOW_H__